
const user=require('../models/user');

var usermodel=user.userModel;

//1.add
async function addUser(user){
    try{
    var data=await usermodel.create(user);

        if(data=={}||data==undefined){
            return {success:false,msg:"用户保存失败"}
        }else{
            return {success:true,user:data}
        }
    }catch(e){
        console.log("add user is error and the error reason is:"+e);
        return {success:false,msg:e};
    }
}
//2.findByName
async function findByName(name){
    try{
       var user=await usermodel.findOne({name:name});
        if(user=={}||user==undefined){
            return {success:false,msg:"查无此人"}
        }else{
            //找到做一个用户确认
            return {success:true,user:user}
        }
    }catch(e){
        return {success:false,msg:e}
    }
}

exports.addUser=addUser;
exports.findByName=findByName;